package com.ems.controller.system;

import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.system.SysNotice;
import com.ems.service.system.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2020/1/2
 * @Description: 处理系统通知信息
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有请求跨域
@RequestMapping("/noticeController")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    //添加通知消息
    @ResponseBody
    @RequestMapping("/addNotice")
    public ResultData addNotice(@RequestBody SysNotice sysNotice){
        noticeService.addNotice(sysNotice);
        return RetunResult.AssemblyData();
    }


    //批量删除指定的消息
    @ResponseBody
    @RequestMapping("/deleteNotice")
    public ResultData deleteNotice(@RequestBody List<SysNotice> list){
        noticeService.deleteNotice(list);
        return RetunResult.AssemblyData();
    }

    //修改通知信息
    @ResponseBody
    @RequestMapping("/updateNoticeById")
    public ResultData updateNoticeById(@RequestBody SysNotice sysNotice){
        noticeService.updateNoticeById(sysNotice);
        return RetunResult.AssemblyData();
    }


    //分页查询通知消息
    @ResponseBody
    @RequestMapping("/findNoticeByPage")
    public ResultData findNoticeByPage(@RequestBody RequestData requestData){
        ReturnPageResult.setPageHelperInfo(requestData);
        List<SysNotice> list = noticeService.findNoticeByPage(requestData.getMap());
        return ReturnPageResult.AssemblyData(list);
    }

    //删除所有未开始的通知
    @ResponseBody
    @RequestMapping("/deleteUnStartNotice")
    public ResultData deleteUnStartNotice(){
        noticeService.deleteUnStartNotice();
        return RetunResult.AssemblyData();
    }

    //删除所有结束的通知
    @ResponseBody
    @RequestMapping("/deleteStretedNotice")
    public ResultData deleteStretedNotice(){
        noticeService.deleteStretedNotice();
        return RetunResult.AssemblyData();
    }


    //根据当前时间查询要通知的内容
    @ResponseBody
    @RequestMapping("/queryNoticeNowTime")
    public ResultData queryNoticeNowTime(){
        List<SysNotice> list = noticeService.queryNoticeNowTime();
        return RetunResult.AssemblyData(list);
    }


}
